
//
//  HHUserManager.m
//  HEHE
//
//  Created by 郭树清 on 17/9/30.
//  Copyright © 2017年 郭树清. All rights reserved.
//

#import "HHUserManager.h"
//#import "DEGLoginViewController.h"
#import "KSNavigationController.h"
#import "KSTabBarController.h"
static NSString * const KeyUserInfo = @"UserInfo";

@implementation HHUserManager
#pragma mark - 单例
+ (HHUserManager *)sharedManager {
    static HHUserManager *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handle = [[HHUserManager alloc] init];
    });
    return handle;
}
+(void)login{
    return [[self sharedManager]logInAccount];
}
-(void)logOutAccount{
    
//    UIWindow *window =[UIApplication sharedApplication].keyWindow;
//    
//    KSNavigationController *nav =[[KSNavigationController alloc]initWithRootViewController:[[DEGLoginViewController alloc]init]];
//    
//    [window setRootViewController:nav];
//
//    [kUserDefaults setValue:@"NO" forKey:LoginStatus];
//    [kUserDefaults synchronize];
    
}
+(void)logout{
    return [[self sharedManager]logOutAccount];

}
-(void)logInAccount{
    UIWindow *window =[UIApplication sharedApplication].keyWindow;
     window.rootViewController =  [[KSTabBarController alloc]init];
    [kUserDefaults setValue:@"YES" forKey:LoginStatus];
    [kUserDefaults synchronize];
}
/** 获取模型*/
+(DELoginModel *)getUserInfo{
    
    return   [[self sharedManager]getInstanceUserInfoModel];
}
-(DELoginModel *)getInstanceUserInfoModel{
    NSDictionary *infoDic = [[NSUserDefaults standardUserDefaults] objectForKey:KeyUserInfo];
    DELoginModel *userInfoModel = [DELoginModel mj_objectWithKeyValues:infoDic];
    
    return userInfoModel;
}

/** 存储用户模型*/
+ (void)saveUserInfo:(DELoginModel *)userInfo{
    [[self sharedManager]SaveUserInfo:userInfo];

}
-(void)SaveUserInfo:(DELoginModel *)userInfo{
    if (userInfo)
    {
        [[NSUserDefaults standardUserDefaults] setObject:userInfo.mj_keyValues forKey:KeyUserInfo];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

@end
